BASS_WASAPI_Init

Initializes a device.

BOOL BASS_WASAPI_Init(
    int device,
    DWORD freq,
    DWORD chans,
    DWORD flags,
    float buffer,
    float period,
    WASAPIPROC *proc,
    void *user
);

Parameters
deviceThe device to use... -1 = default output device, -2 = default input device. BASS_WASAPI_GetDeviceInfo can be used to enumerate the available devices.
freqThe sample rate... 0 = "mix format" sample rate
chansThe number of channels... 0 = "mix format" channels, 1 = mono, 2 = stereo, etc.
flagsAny combination of these flags.
BASS_WASAPI_AUTOFORMATAutomatically choose another sample format if the specified format is not supported. If possible, a higher sample rate than freq will be used, rather than a lower one.
BASS_WASAPI_BUFFEREnable double buffering, for use by BASS_WASAPI_GetData and BASS_WASAPI_GetLevel. This requires the BASS "no sound" device to have been initilized, via BASS_Init.
BASS_WASAPI_EXCLUSIVEInitialize the device in exclusive mode, else shared mode.
bufferThe length of the device's buffer in seconds. This is a minimum and the driver may choose to use a larger buffer; BASS_WASAPI_GetInfo can be used to confirm what the buffer size is. For an output device, the buffer size determines the latency.
periodThe interval (in seconds) between callback function calls... 0 = use default. If the specified period is below the minimum update period, it will automatically be raised to that.
procThe callback function to provide/receive the sample data... NULL = use BASS_WASAPI_PutData to feed the output.
userUser instance data to pass to the callback function.

Return value
If the device was successfully initialized, TRUE is returned, else FALSE is returned. Use BASS_ErrorGetCode to get the error code.

Error codes
BASS_ERROR_WASAPIWASAPI is not available.
BASS_ERROR_DEVICEdevice is invalid.
BASS_ERROR_ALREADYThe device has already been initialized. BASS_WASAPI_Free must be called before it can be initialized again.
BASS_ERROR_ILLPARAMA WASAPIPROC must be provided for an input device.
BASS_ERROR_DRIVERThe driver could not be initialized.
BASS_ERROR_FORMATThe specified format is not supported by the device. If the BASS_WASAPI_AUTOFORMAT flag was specified, no other format could be found either.
BASS_ERROR_BUSYThe device is already in use, eg. another process may have initialized it in exclusive mode.
BASS_ERROR_INITThe BASS "no sound" device has not been initialized.
BASS_ERROR_UNKNOWNSome other mystery problem!

Remarks
For convenience, devices are always initialized to use their highest sample resolution and that is then converted to 32-bit floating-point, so that WASAPIPROC callback functions and the BASS_WASAPI_PutData and BASS_WASAPI_GetData functions are always dealing with the same sample format. The device's sample format can be obtained via BASS_WASAPI_GetInfo.

WASAPI does not support arbitrary sample formats, like DirectSound does. In particular, only the "mix format" (available from BASS_WASAPI_GetDeviceInfo) is generally supported in shared mode. BASS_WASAPI_CheckFormat can be used to check whether a particular sample format is supported. The BASSmix add-on can be used to play (or record) in otherwise unsupported sample formats, as well as playing multiple sources.

A loopback device can only be used when the corresponding output device is not being used in exclusive mode, and it will only deliver data when the ouput device does; if the output device produces no data, then the loopback device will capture no data.

The initialized device will not begin processing data until BASS_WASAPI_Start is called.

Simultaneously using multiple devices is supported in the BASS API via a context switching system; instead of there being an extra "device" parameter in the function calls, the device to be used is set prior to calling the functions. BASS_WASAPI_SetDevice is used to switch the current device. When successful, BASS_WASAPI_Init automatically sets the current thread's device to the one that was just initialized.

When using the default output or input device, BASS_WASAPI_GetDevice can be used to find out which device it was mapped to.

Example
Initialize BASSWASAPI to use the default output device in exclusive mode, with 44100hz stereo output, and a 500ms buffer with the default period.

BASS_Init(-1, 44100, 2, BASS_WASAPI_EXCLUSIVE, 0.5, 0, MyWasapiProc, NULL);

See also
BASS_WASAPI_CheckFormat, BASS_WASAPI_Free, BASS_WASAPI_GetDeviceInfo, BASS_WASAPI_GetInfo, BASS_WASAPI_Start, WASAPIPROC callback